<template>
<div>
login
<van-form >
        <van-field
          v-model="username"
          name="用户名"
          label="用户名"
          placeholder="用户名"
          
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          
        />
        <div style="margin: 16px">
          <van-button round block type="info" @click="denglu" style="width:100px;float: left;"
            >登录</van-button
          >
        </div>
      </van-form>
</div>
</template>

<script>
import { Toast } from "vant";
import api from '@/api/api'
export default{
    data(){
        return{
            username:'',
            password:'',

        }
    },
    methods:{
        denglu(){
      api.getOne(this.username,this.password).then(res=>{
        console.log(res)
        console.log(res.data.length)//长度为1代表登录成功，为0则登录失败
        // console.log(res.data[0].id)
        if(res.data.length ==1){
          this.userid = res.data[0].id
          Toast('登录成功')
          this.$router.push({ path: '/home/'+this.userid })
        }
        else
        {
          Toast('登录失败')
          
        }
      })
    },
    }

}
</script>